package com.ebelter.seneo.models.updateApp;


import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.ebelter.btcomlib.models.beans.UpdateVersionBean;
import com.ebelter.btcomlib.models.https.NetUtils;
import com.ebelter.btcomlib.models.https.interfaces.HttpResponse;
import com.ebelter.btcomlib.utils.AppUtils;
import com.ebelter.btcomlib.utils.NumUtils;

import com.ebelter.btcomlib.utils.log.LogUtils;
import com.ebelter.btcomlib.views.dialogs.TextTipDialog;
import com.ebelter.seneo.models.SeneoNet;


public class Updater {


    private static final String TAG = "Updater";




    public void checkVersion(final Context context, final IGetVersion getVersion){


        if(getVersion==null||context==null)return;

        final int verCode= AppUtils.getVersionCode(context);//获取当前版本号
        LogUtils.i(TAG,"appVerCode --"+verCode);

        SeneoNet.getIntance().getVersionJosn(context, new HttpResponse<UpdateVersionBean>() {
            @Override
            public void result(boolean isRequestSuccess, String requestDes, UpdateVersionBean updateVersionBean,String s) {
                if (isRequestSuccess){
                    LogUtils.i(TAG,"服务器上的json--"+updateVersionBean.toString());


                    if (NumUtils.string2Int(updateVersionBean.getVerCode())>verCode){
                        //说明有新版本
                        getVersion.callback(true,updateVersionBean);
                    }else {
                        //说明没有最新的
                        getVersion.callback(false,updateVersionBean);
                    }
                }else {
                    getVersion.callback(false,null);
                }
            }
        });




    }






    public interface IGetVersion{
        void callback(boolean needUpdate,UpdateVersionBean versionBean);
    }
}
